﻿<%@ Page Title="" Language="C#" MasterPageFile="~/resumemanager/resume.master" Inherits="WebManager.BasePage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<%@ Import Namespace="TalentPools.Model" %>
<%@ Import Namespace="TalentPools.BLL" %>
<script runat="server">
    public int RecordId
    {
        get
        {
            return Convert.ToInt32(ViewState["recordid"]);
        }
        set
        {
            ViewState["recordid"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!MyUserLogin())
        {
            Response.Redirect("~/Index.aspx");
            return;
        }
        if (!IsPostBack)
        {
            this.txteditbtime.Attributes.Add("ReadOnly", "true");
            this.txteditbtime.Attributes.Add("ReadOnly", "true");
            this.txtrecordbegintime.Attributes.Add("ReadOnly", "true");
            this.txtrecordendtime.Attributes.Add("ReadOnly", "true");
            ManagerVoid();
            string qstr = QueryString("Action");
            switch (qstr)
            {
                case "Add":
                    AddP.Visible = true;
                    manageP.Visible = false;
                    EditP.Visible = false;
                    break;
                case "Edit":
                    EditVoid();
                    break;
                case "Del":
                    DelVoid();
                    break;
            }
        }
    }
    private void ManagerVoid()
    {
        AddP.Visible = false;
        EditP.Visible = false;
        manageP.Visible = true;
        RP1.DataSource = new RecordManager().GetRecord(Convert.ToInt32(Session["resumeId"]));
        RP1.DataBind();
    }
    private void EditVoid()
    {
        AddP.Visible = false;
        EditP.Visible = true;
        manageP.Visible = false;
        int id = Convert.ToInt32(QueryString("id"));
        RecordId = id;
        record re = new RecordManager().GetRecord(Convert.ToInt32(Session["resumeId"]), id);
        txtedittitle.Text = re.title;
        txteditbtime.Text = re.beginTime.ToShortDateString();
        txteditetime.Text = re.endTime.ToShortDateString();
        txteditcontent.Text = re.content.Trim();
        txteditdes.Text = re.details;

    }
    private void DelVoid()
    {
        int id = Convert.ToInt32(QueryString("id"));
        if (new RecordManager().DeleteRecord(id))
        {
            ManagerVoid();
        }
    }
    private string sf()
    {
        string des = Eval("details").ToString();
        if (des.Length>=15)
        {
            return des.Substring(0, 14);
        }
        return des;
    }
    protected void btnsubmit_record_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            record re = new record();
            re.resumeId = Convert.ToInt32(Session["resumeId"]);
            re.title = txtrecordtitle.Text.Trim();
            re.beginTime = Convert.ToDateTime(txtrecordbegintime.Text.Trim());
            re.endTime = Convert.ToDateTime(txtrecordendtime.Text.Trim());
            re.content = txtrecordcontent.Text.Trim();
            re.details = txtrecorddes.Text.Trim();
            if (new CreateresumeManager().creatRecord(re))
            {
                lblrecord.Text = "操作成功！";
            }
            else
            {
                lblrecord.Text = "添加工作履历失败，如果确认天下信息无误，请联系管理员解决问！";
            }
        }
    }

    protected void btnsubmit_edit_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            record re = new record();
            re.recordid = RecordId;
            re.resumeId = Convert.ToInt32(Session["resumeId"]);
            re.title = txtedittitle.Text.Trim();
            re.beginTime = Convert.ToDateTime(txteditbtime.Text.Trim());
            re.endTime = Convert.ToDateTime(txteditetime.Text.Trim());
            re.content = txteditcontent.Text.Trim();
            re.details = txteditdes.Text.Trim();
            if (new alertResumeManager().updaterec(re))
            {
                Label1.Text = "操作成功！";
            }
            else
            {
                Label1.Text = "修改工作履历失败，如果确认天下信息无误，请联系管理员解决问！";
            }
        }
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager runat="server">
    </asp:ScriptManager>
    <table width='100%' border='0' align='center' cellpadding='4' cellspacing='1' class='border'>
        <tr class='topbg'>
            <td colspan="2" align='center'>
                <strong class="Glow">工 作 履 历 管 理</strong>
            </td>
        </tr>
        <tr class='tdbg'>
            <td width='70'>
                <strong>导航：</strong>
            </td>
            <td>
                <a href="?Action=Add">添加工作履历</a> | <a href="EditRecordInfo.aspx">工作履历列表</a>
            </td>
        </tr>
    </table>
    <asp:Panel ID="AddP" runat="server" Visible="false">
        <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
            <tr class='tdbg'>
                <td colspan="2" class="topbg2">
                    <div align="center" class="Glow">
                        <strong>新 增 工 作 履 历</strong></div>
                </td>
            </tr>
            <tr class='tdbg'>
                <td width="23%" class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>信息标题：</div>
                </td>
                <td width="77%" class="tdbg2">
                    <asp:TextBox ID="txtrecordtitle" runat="server"></asp:TextBox>
                    <span class="style4">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtrecordtitle"
                            ErrorMessage="请输入工作履历描述性的标题"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>开始时间：</div>
                </td>
                <td class="tdbg2">
                    <asp:TextBox ID="txtrecordbegintime" runat="server"></asp:TextBox>
                    <asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtrecordbegintime" runat="server">
                    </asp:CalendarExtender>
                    <span class="style4">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="txtrecordbegintime"
                            runat="server" ErrorMessage="请选择工作开始时间"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>结束时间：</div>
                </td>
                <td class="tdbg2">
                    <asp:TextBox ID="txtrecordendtime" runat="server"></asp:TextBox>
                    <asp:CalendarExtender ID="CalendarExtender2" TargetControlID="txtrecordendtime" runat="server">
                    </asp:CalendarExtender>
                    <span class="style4">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator8" ControlToValidate="txtrecordendtime"
                            runat="server" ErrorMessage="请选择工作结束时间"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>工作内容：</div>
                </td>
                <td class="tdbg2">
                    <asp:TextBox ID="txtrecordcontent" runat="server"></asp:TextBox>
                    <span class="style4" style="color: #333">
                        <asp:RequiredFieldValidator ControlToValidate="txtrecordcontent" ID="RequiredFieldValidator9"
                            runat="server" ErrorMessage="请输入工作内容"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>详细描述：</div>
                </td>
                <td class="tdbg2" style="width: 482px">
                    <asp:TextBox ID="txtrecorddes" runat="server" Height="138px" TextMode="MultiLine"
                        Width="343px"></asp:TextBox>
                    <span class="style4" style="color: #333">
                        <asp:RequiredFieldValidator ControlToValidate="txtrecorddes" ID="RequiredFieldValidator10"
                            runat="server" ErrorMessage="请输入工作描述"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
        </table>
        <br />
        <table width="100%" border="0">
            <tr>
                <td>
                    <div align="center">
                        &nbsp;<asp:Button ID="btnsubmit_record" runat="server" Text="提 交" OnClick="btnsubmit_record_Click" />
                        &nbsp;
                        <label>
                            <input type="reset" name="Submit2" value="重 置" /><br />
                            <asp:Label ID="lblrecord" runat="server" ForeColor="Red"></asp:Label></label></div>
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="EditP" runat="server" Visible="false">
        <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
            <tr class='tdbg'>
                <td colspan="2" class="topbg2">
                    <div align="center" class="Glow">
                        <strong>修 改 工 作 履 历</strong></div>
                </td>
            </tr>
            <tr class='tdbg'>
                <td width="23%" class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>信息标题：</div>
                </td>
                <td width="77%" class="tdbg2">
                    <asp:TextBox ID="txtedittitle" runat="server"></asp:TextBox>
                    <span class="style4">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtedittitle"
                            ErrorMessage="请输入工作履历描述性的标题"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>开始时间：</div>
                </td>
                <td class="tdbg2">
                    <asp:TextBox ID="txteditbtime" runat="server"></asp:TextBox>
                    <asp:CalendarExtender TargetControlID="txteditbtime" ID="CalendarExtender3" runat="server">
                    </asp:CalendarExtender>
                    <span class="style4">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txteditbtime"
                            runat="server" ErrorMessage="请选择工作开始时间"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>结束时间：</div>
                </td>
                <td class="tdbg2">
                    <asp:TextBox ID="txteditetime" runat="server"></asp:TextBox>
                    <asp:CalendarExtender TargetControlID="txteditetime" ID="CalendarExtender4" runat="server">
                    </asp:CalendarExtender>
                    <span class="style4">
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txteditetime"
                            runat="server" ErrorMessage="请选择工作结束时间"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>工作内容：</div>
                </td>
                <td class="tdbg2">
                    <asp:TextBox ID="txteditcontent" runat="server"></asp:TextBox>
                    <span class="style4" style="color: #333">
                        <asp:RequiredFieldValidator ControlToValidate="txteditcontent" ID="RequiredFieldValidator4"
                            runat="server" ErrorMessage="请输入工作内容"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
            <tr class='tdbg'>
                <td class="tdbg1">
                    <div align="right">
                        <span class="style4">*</span>详细描述：</div>
                </td>
                <td class="tdbg2" style="width: 482px">
                    <asp:TextBox ID="txteditdes" runat="server" Height="138px" TextMode="MultiLine" Width="343px"></asp:TextBox>
                    <span class="style4" style="color: #333">
                        <asp:RequiredFieldValidator ControlToValidate="txteditdes" ID="RequiredFieldValidator5"
                            runat="server" ErrorMessage="请输入工作描述"></asp:RequiredFieldValidator>
                    </span>
                </td>
            </tr>
        </table>
        <br />
        <table width="100%" border="0">
            <tr>
                <td>
                    <div align="center">
                        &nbsp;<asp:Button ID="btnsubmit_edit" runat="server" Text="提 交" OnClick="btnsubmit_edit_Click" />
                        &nbsp;
                        <label>
                            <input type="reset" name="Submit2" value="重 置" /><br />
                            <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label></label></div>
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="manageP" runat="server" Width="100%" Visible="False">
        <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
            <tr class='topbg2'>
                <td width="7%" align='center' style="height: 24px">
                    <strong class="Glow">序号</strong>
                </td>
                <td width="12%" align='center' style="color: #000000; height: 24px">
                    <strong class="Glow">标题</strong>
                </td>
                <td width="18%" align='center' style="height: 24px">
                    <strong class="Glow">时间</strong>
                </td>
                <td width="18%" align='center' style="height: 24px">
                    <strong class="Glow">内容</strong>
                </td>
                <td width="25%" align='center' style="height: 24px">
                    <strong class="Glow">描述</strong>
                </td>
                <td width="14%" align='center' style="height: 24px">
                    <strong class="Glow">操作</strong>
                </td>
            </tr>
            <asp:Repeater ID="RP1" runat="server">
                <ItemTemplate>
                    <tr class='tdbg'>
                        <td align='center'>
                            <%#Eval("recordid")%>
                        </td>
                        <td align='center'>
                            <%#Eval("title") %>
                        </td>
                        <td>
                            <%#SetTimeFormat(Convert.ToDateTime(Eval("beginTime"))) %>--<%#SetTimeFormat(Convert.ToDateTime(Eval("endTime"))) %></td>
                        <td>
                            <%#Eval("content") %>
                        </td>
                        <td align='center'>
                            <%#sf() %>
                        </td>
                        <td align='center'>
                            <a href="EditRecordInfo.aspx?id=<%#Eval("recordid")%>&amp;Action=Edit">修改</a> |
                            <a href="EditRecordInfo.aspx?id=<%#Eval("recordid") %>&amp;Action=Del" onclick="return confirm('确定要删除此项吗？此操作不可逆。');">
                                删除</a>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
    </asp:Panel>
</asp:Content>
